#include"timeStamp.h"
#include<ctime>
#include<iostream>
#include"public.h"
TimeStamp::TimeStamp() : secondSinceEpoch_(0)
{

}
TimeStamp::TimeStamp(uint64_t secondSinceEpoch)
{
    secondSinceEpoch_ = secondSinceEpoch;
}
/* secondSinceEpoch -> localtime -> struct tm -> string */
std::string TimeStamp::ToString() const
{
    struct tm t;
    localtime_r(&secondSinceEpoch_, &t);
    /* 最好写成2的幂次，为了总线取数据一次取完 */
    char buf[SMALL_BUF_LEN] = {0};
    snprintf(buf, SMALL_BUF_LEN, "[%04d/%02d/%02d %02d:%02d:%02d]",
        t.tm_year + 1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
    return buf;
}
TimeStamp TimeStamp::Now()
{
    return TimeStamp(time(NULL));
}